// *********************************************************************
// >> File Name: /home/diabio/project/al_cache/al_cache/arc_cache/arc_cache_node.h
// >> Author: diabiolin
// >> Created Time: Fri 25 Apr 2025 08:58:54 PM CST
// >> Description:
// *********************************************************************
#pragma once
#include <memory>

namespace al_cache{

template <typename Key, typename Value>
class ArcNode{
public:
	ArcNode() 
		: accessCount_(1)
		, prev_()
		, next_(nullptr)
		{}
	
	ArcNode(Key key, Value value)
		: key_(key)
		, value_(value)
		, accessCount_(1)
		, prev_()
		, next_(nullptr)
		{}
	
	// 一些访问器 
	Key getKey() const {
		return key_;
	}

	Value getValue() const {
		return value_;
	}

	size_t getAccessCount() const {
		return accessCount_;
	}

	void setValue(const Value& value) {
		value_ = value;
	}

	void incrementAccessCount() {
		accessCount_++;
	}

	template<typename K, typename V> friend class ArcLruPart;
	template<typename K, typename V> friend class ArcLfuPart;
	
private:
	Key key_;
	Value value_;
	size_t accessCount_;
	std::weak_ptr<ArcNode> prev_; // 使用weak_ptr避免循环引用
	std::shared_ptr<ArcNode> next_;
};

} // namespace al_cache
